<?php 

class Moderator extends Model{
	function Moderator(){
		parent::Model();
	}

	function getlist($table){
		$sql = "SELECT * FROM $table";
		$query = $this->db->query($sql);
		return $query;
	}

	function getClasses($table){
		$sql = "SELECT subjectid, subjectname, description FROM $table";
		$query = $this->db->query($sql);
		return $query;
	}

	function insertClass($table,$contents){
		$this->db->insert($table, $contents);
	}

	function deleteClass($toDelete){
		$limit = count($toDelete);
		for ($i = 0; $i < $limit; $i++){
			$delete = $toDelete[$i];
			$subject = "DELETE FROM subjects WHERE subjectid = $delete";
			$this->db->query($subject);
		}
	}
	
	function deleteThisClass($id){
		$sql = "DELETE FROM subjects WHERE subjectid = $id";
		$this->db->query($sql);
		return $query;
	}

	function getSchedules(){
		$sql = "select * from (select email, lastname, firstname, studentid, subjectid,date,time,adminstatus from teachers INNER JOIN schedule on teachers.userid = schedule.teacherid where adminstatus = 'pending') AS derived INNER JOIN subjects ON derived.subjectid = subjects.subjectid";
		$query = $this->db->query($sql);
		return $query;
	}

	function viewAllSchedules(){
		$sql = "select * from (select email, lastname, firstname, studentid, subjectid,date,time,adminstatus from teachers INNER JOIN schedule on teachers.userid = schedule.teacherid) AS derived INNER JOIN subjects ON derived.subjectid = subjects.subjectid";
		$query = $this->db->query($sql);
		return $query;
	}

	function getPending($table, $who){
		$sql = "select * from $table";
		$query = $this->db->query($sql);
		return $query;
	}

	function updateStatus($table, $status, $student){
			return $this->db->update($table, $status, array('email'=>$student));
	}

	function updateSchedule($table, $status, $teacherid, $date, $time){
		return $this->db->update($table, $status, array('teacherid'=>$teacherid, 'date'=>$date, 'time'=>$time));
	}

	function addAnnouncement($table, $contents){
		$this->db->insert($table, $contents);	
	}
}

?>
